//
//  HZDateFormatter.m
//  testheaderAndfooter
//
//  Created by huazi on 14-3-21.
//  Copyright (c) 2014年 huifu. All rights reserved.
//

#import "HZDateFormatter.h"

@implementation HZDateFormatter
+(NSString *)returnNowDate
{
    NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyyMMddHHmm"];
    NSString *returnStr =[dateFormatter stringFromDate:[NSDate date]];
    return returnStr;
}
+(NSString *)returnNowDateType:(NSString *)strType
{
    NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:strType];
    NSString *returnStr =[dateFormatter stringFromDate:[NSDate date]];
    return returnStr;
}
+(NSString *)returnStrFromDate:(NSDate *)date andStr:(NSString *)strType
{
    NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:strType];
    NSString *returnStr =[dateFormatter stringFromDate:date];
    return returnStr;

}
+(NSString *)returnStrFromSecond:(NSString *)sendTime
{
    
    NSDate *dateSend =[NSDate dateWithTimeIntervalSince1970:[sendTime doubleValue]/1000];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit |NSHourCalendarUnit |NSMinuteCalendarUnit;
    NSDateComponents *cmp1 = [calendar components:unitFlags fromDate:dateSend];
    NSDateComponents *cmp2 = [calendar components:unitFlags fromDate:[NSDate date]];
    
    // 2.格式化日期
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    if ([cmp1 day] == [cmp2 day]) { // 今天
        formatter.dateFormat = @"今天 HH:mm";
    } else if ([cmp1 year] == [cmp2 year]) { // 今年
        formatter.dateFormat = @"MM-dd HH:mm";
    } else {
        formatter.dateFormat = @"yyyy-MM-dd";
    }
    NSString *time = [formatter stringFromDate:dateSend];
    
 return time;
    
   
    
    
}
+(NSString *)returnStrFromTimeStr:(NSString *)sendTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyyMMddHHmm";
    NSDate *dateSend =[formatter dateFromString:sendTime];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit |NSHourCalendarUnit |NSMinuteCalendarUnit;
    NSDateComponents *cmp1 = [calendar components:unitFlags fromDate:dateSend];
    NSDateComponents *cmp2 = [calendar components:unitFlags fromDate:[NSDate date]];
    
    // 2.格式化日期
   
    if ([cmp1 day] == [cmp2 day]) { // 今天
        formatter.dateFormat = @"今天";
    } else if ([cmp1 year] == [cmp2 year]) { // 今年
        formatter.dateFormat = @"MM-dd";
    } else {
        formatter.dateFormat = @"yyyy-MM-dd";
    }
    NSString *time = [formatter stringFromDate:dateSend];
    
    return time;

}

+(NSString *)returnSecondNowDateSince1970
{
    NSTimeInterval second =[[NSDate date] timeIntervalSince1970]*1000;
    return [NSString stringWithFormat:@"%.0f",second];
}
+(NSString *)returnSecondNowDateToLaterDate:(NSString *)laterDate
{
    
    NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSTimeInterval second =[[NSDate date] timeIntervalSinceDate:[dateFormatter dateFromString:laterDate]];
    return [NSString stringWithFormat:@"%.0f",second];
    
}
+(NSDate *)returnDateWithTimeStr:(NSString *)strTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyy.MM.dd HH:mm";
    NSDate *date =[formatter dateFromString:strTime];
    return date;
}
+(NSString *)returnDateStrFromTimeStr:(NSString *)sendTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyyMMddHHmmss";
    NSDate *dateSend =[formatter dateFromString:sendTime];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit |NSHourCalendarUnit |NSMinuteCalendarUnit;
    NSDateComponents *cmp1 = [calendar components:unitFlags fromDate:dateSend];
    NSDateComponents *cmp2 = [calendar components:unitFlags fromDate:[NSDate date]];
    
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    if ([cmp1 day] == [cmp2 day]) { // 今天
        formatter1.dateFormat = @"今天 HH:mm";
    } else if ([cmp1 year] == [cmp2 year]) { // 今年
        formatter1.dateFormat = @"MM-dd HH:mm";
    } else {
        formatter1.dateFormat = @"yyyy-MM-dd";
    }
    NSString *time = [formatter1 stringFromDate:dateSend];
    return time;
}

+(NSString *)returnDateStrDateFromTimeStr:(NSString *)sendTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyyMMddHHmm";
    NSDate *dateSend =[formatter dateFromString:sendTime];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    formatter1.dateFormat = @"yyyy/MM/dd";
    NSString *time = [formatter1 stringFromDate:dateSend];
    return time;

}
+(NSString *)returnDateStrTimeFromTimeStr:(NSString *)sendTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyyMMddHHmm";
    NSDate *dateSend =[formatter dateFromString:sendTime];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    formatter1.dateFormat = @"HH:mm";
    NSString *time = [formatter1 stringFromDate:dateSend];
    return time;
}
+(NSString *)returnDateStrWithType:(NSString *)sendTime AndType:(NSString *)type
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyyMMddHHmm";
    NSDate *dateSend =[formatter dateFromString:sendTime];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    formatter1.dateFormat = type;
    NSString *time = [formatter1 stringFromDate:dateSend];
    return time;
}
+(NSString *)returnDateStrWithType2:(NSString *)sendTime AndType:(NSString *)type
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyyMMddHHmmss";
    NSDate *dateSend =[formatter dateFromString:sendTime];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    formatter1.dateFormat = type;
    NSString *time = [formatter1 stringFromDate:dateSend];
    return time;
}
+(NSString *)returnDateStrDateFromTimeStr2:(NSString *)sendTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyyMMddHHmmss";
    NSDate *dateSend =[formatter dateFromString:sendTime];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    formatter1.dateFormat = @"yyyy/MM/dd";
    NSString *time = [formatter1 stringFromDate:dateSend];
    return time;
    
}
+(NSString *)returnDateStrTimeFromTimeStr2:(NSString *)sendTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat =@"yyyyMMddHHmmss";
    NSDate *dateSend =[formatter dateFromString:sendTime];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    formatter1.dateFormat = @"HH:mm";
    NSString *time = [formatter1 stringFromDate:dateSend];
    return time;
}
+(NSString *)returnNowTimestamp
{
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval a=[dat timeIntervalSince1970]*1000;
    NSString *timeString = [NSString stringWithFormat:@"%.0f", a];
    return timeString;
}
@end
